//
//  SYShiXunHeaderView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/19.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYShiXunHeaderView.h"
#import "SYFuntionHeaderView.h"


@interface SYShiXunHeaderView ()

@property (strong, nonatomic) UILabel *headerLab;//小组名称
@property (strong, nonatomic) UILabel *xiaozuLab;
@property (nonatomic, strong) UIButton *addBtn;//添加按钮
@property (strong, nonatomic) SYFuntionHeaderView *headerViewKS;//开始
@property (strong, nonatomic) SYFuntionHeaderView *headerViewJS;//结束
@property (strong, nonatomic) SYFuntionHeaderView *headerViewCY;//成员数量
@property (strong, nonatomic) SYFuntionHeaderView *headerViewXZ;//小组简介
@property (strong, nonatomic) SYFuntionHeaderView *headerViewZT;//当前状态

@property (strong, nonatomic) UIButton *xiugaiBtn;//修改按钮



@property (assign, nonatomic) SYShiXunHeaderViewType staus;

@end


@implementation SYShiXunHeaderView

- (instancetype)init {
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
        [self initSubView];
    }
    return self;
}

- (void)initSubView {
    [self addSubview:self.headerLab];
    [self.headerLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.top.equalTo(self.mas_top).offset(18);
    }];
    CGFloat height = 40;
    CGFloat width = 330;
    //开始日期
    [self addSubview:self.headerViewKS];
    [self.headerViewKS mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerLab.mas_bottom).offset(10);
        make.left.equalTo(self.mas_left).offset(70);
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(height);
    }];
    //结束日期
    [self addSubview:self.headerViewJS];
    [self.headerViewJS mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headerViewKS.mas_centerY);
        make.left.equalTo(self.mas_centerX).offset(70);
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(height);
    }];
    //成员数量
    [self addSubview:self.headerViewCY];
    [self.headerViewCY mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.headerViewKS.mas_centerX);
        make.trailing.equalTo(self.headerViewKS.mas_trailing);
        make.top.equalTo(self.headerViewKS.mas_bottom).offset(10);
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(height);
    }];
    //小组简介
    [self addSubview:self.headerViewXZ];
    [self.headerViewXZ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.headerViewKS.mas_centerX);
        make.trailing.equalTo(self.headerViewKS.mas_trailing);
        make.top.equalTo(self.headerViewCY.mas_bottom).offset(10);
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(height);
    }];
    //当前状态
    [self addSubview:self.headerViewZT];
    [self.headerViewZT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.headerViewJS.mas_trailing);
        make.centerY.equalTo(self.headerViewCY.mas_centerY);
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(height);
    }];
    
    //提交成果
    [self addSubview:self.tijiaoChengGuoBtn];
    [self.tijiaoChengGuoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.headerViewZT.mas_trailing).offset(-10);
        make.centerY.equalTo(self.headerViewZT);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(70);
    }];
    
    //小组成员
    [self addSubview:self.xiaozuLab];
    [self.xiaozuLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.top.equalTo(self.headerViewXZ.mas_bottom).offset(18);
    }];
    
    [self addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-40);
        make.left.equalTo(self.mas_left).offset(20);
        make.right.equalTo(self.mas_right).offset(-20);
        make.height.mas_equalTo(40);
    }];
    
    //添加成员
    [self addSubview:self.addBtn];
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topView.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-50);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(40);
    }];
    
    [self addSubview:self.biaoBgView];
    [self.biaoBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.left.equalTo(self.mas_left).offset(0);
        make.right.equalTo(self.mas_right).offset(0);
        make.height.mas_equalTo(40);
    }];
    
    [self addSubview:self.biaoView];
    [self.biaoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.left.equalTo(self.mas_left).offset(14);
        make.right.equalTo(self.mas_right).offset(-14);
        make.height.mas_equalTo(40);
    }];
    
    
    
    //修改按钮
    [self addSubview:self.xiugaiBtn];
    [self.xiugaiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headerLab.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-50);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(80);
    }];
}

- (void)setIndex:(NSInteger)index {
    self.biaoView.type = index;
    if (index == 1) { //如果完成，添加成员按钮隐藏
        
    } else {
        
    }
}

- (void)shixunHeaderViewType:(SYShiXunHeaderViewType)type index:(NSInteger)index {
    _staus = type;
    self.biaoView.type = index;
    if (type == SYShiXunHeaderViewTypeDefault) {//默认都隐藏，如果完成
        self.addBtn.hidden = YES;
        self.xiugaiBtn.hidden = YES;
    } else if (type == SYShiXunHeaderViewTypeXiuGai) { //没有完成，显示修改
        self.addBtn.hidden = NO;
        self.xiugaiBtn.hidden = NO;
    } else if (type == SYShiXunHeaderViewTypeDetails) {//详情
        self.addBtn.hidden = YES;
        self.xiugaiBtn.hidden = NO;
        [self.xiugaiBtn setTitle:@"师训详情" forState:UIControlStateNormal];
    } else if (type == SYShiXunHeaderViewTypeJiaoYanWeiWanCheng) {//教研 进行中状态
        self.xiugaiBtn.hidden = NO;
        self.addBtn.hidden = NO;//管理成员
        [self.addBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [self.addBtn setTitle:@"管理成员" forState:UIControlStateNormal];
        [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#20B097"] forState:0];
        self.tijiaoChengGuoBtn.hidden = NO;
    }
}

//添加成员，管理成员,修改按钮
- (void)addBtnClick:(UIButton *)send {
    NSString *btnName = send.titleLabel.text;
    SYShiXunHeaderSelectType type = -1;
    if ([btnName containsString:@"添加成员"]) {
        type = SYShiXunHeaderSelectTypeAddChengYuan;
    } else if ([btnName containsString:@"管理成员"]) {
        type = SYShiXunHeaderSelectTypeGuanLiChengYuan;
    } else {
        type = SYShiXunHeaderSelectTypXiuGai;//修改
    }
    if (self.block) {
        self.block(type);
    }
    
}
//提交成果
- (void)tijiaochengguoBtnClick {
    if (self.block) {
        self.block(SYShiXunHeaderSelectTypeTiJiaoChengGuo);
    }
}


- (UILabel *)headerLab {
    if (!_headerLab) {
        _headerLab = [UILabel titleColour:TITLECOLOR
                               titleFount:14
                                 pingfang:@"PingFang-SC-Medium"
                                alignment:NSTextAlignmentCenter
                                titleLine:1];
        _headerLab.text = @"吴亚茹2019师训小组";
    }
    return _headerLab;
}
//开始日期
- (SYFuntionHeaderView *)headerViewKS {
    if (!_headerViewKS) {
        _headerViewKS = [[SYFuntionHeaderView alloc] init];
        _headerViewKS.titleLab.text = @"开始日期: ";
        _headerViewKS.textField.hidden = YES;
    }
    return _headerViewKS;
}
//结束日期
- (SYFuntionHeaderView *)headerViewJS {
    if (!_headerViewJS) {
        _headerViewJS = [[SYFuntionHeaderView alloc] init];
        _headerViewJS.titleLab.text = @"结束日期: ";
        _headerViewJS.textField.hidden = YES;
    }
    return _headerViewJS;
}
//成员数量 headerViewXZ
- (SYFuntionHeaderView *)headerViewCY {
    if (!_headerViewCY) {
        _headerViewCY = [[SYFuntionHeaderView alloc] init];
        _headerViewCY.titleLab.text = @"成员数量: ";
        _headerViewCY.contLab.text = @"5";
        _headerViewCY.contLab.textColor = [UIColor colorWithHexString:@"#FF4800"];
        _headerViewCY.textField.hidden = YES;
    }
    return _headerViewCY;
}
//小组简介
- (SYFuntionHeaderView *)headerViewXZ {
    if (!_headerViewXZ) {
        _headerViewXZ = [[SYFuntionHeaderView alloc] init];
        _headerViewXZ.titleLab.text = @"小组简介: ";
        _headerViewXZ.contLab.text = @"好好学习，天天向上";
        _headerViewXZ.textField.hidden = YES;
    }
    return _headerViewXZ;
}

- (SYFuntionHeaderView *)headerViewZT {
    if (!_headerViewZT) {
        _headerViewZT = [[SYFuntionHeaderView alloc] init];
        _headerViewZT.titleLab.text = @"当前状态: ";
        _headerViewZT.contLab.text = @"进行中";
        _headerViewZT.contLab.textColor = [UIColor colorWithHexString:@"#FF4800"];
        _headerViewZT.textField.hidden = YES;
    }
    return _headerViewZT;
}
- (UILabel *)xiaozuLab {
    if (!_xiaozuLab) {
        _xiaozuLab = [UILabel titleColour:TITLECOLOR
                               titleFount:14
                                 pingfang:@"PingFang-SC-Medium"
                                alignment:NSTextAlignmentCenter
                                titleLine:1];
        _xiaozuLab.text = @"小组成员";
        
    }
    return _xiaozuLab;
}
- (UIButton *)addBtn {
    if (!_addBtn) {
        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addBtn addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [_addBtn setImage:[UIImage imageNamed:@"add_teach"] forState:UIControlStateNormal];
        //        _addBtn.hidden = YES;
        _addBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_addBtn setTitleColor:TITLECOLOR forState:0];
        [_addBtn setTitle:@" 添加成员" forState:UIControlStateNormal];
    }
    return _addBtn;
}

- (SYBiaoTiView *)biaoView {
    if (!_biaoView) {
        _biaoView = [[SYBiaoTiView alloc] init];
    }
    return _biaoView;
}
//修改
- (UIButton *)xiugaiBtn {
    if (!_xiugaiBtn) {
        _xiugaiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_xiugaiBtn addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _xiugaiBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_xiugaiBtn setTitleColor:[UIColor colorWithHexString:@"#20B097"] forState:0];
        [_xiugaiBtn setTitle:@"修改" forState:UIControlStateNormal];
        
    }
    return _xiugaiBtn;
}

- (SYTopView *)topView {
    if (!_topView) {
        _topView = [[SYTopView alloc] init];
        _topView.titleLab.text = @"小组成员";
        _topView.fgxView.hidden = YES;
        _topView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
    }
    return _topView;
}

//占位图view
- (UIView *)biaoBgView {
    if (!_biaoBgView) {
        _biaoBgView = [[UIView alloc] init];
        _biaoBgView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
        _biaoBgView.hidden = YES;
    }
    return _biaoBgView;
}
//提交成果
- (UIButton *)tijiaoChengGuoBtn {
    if (!_tijiaoChengGuoBtn) {
        _tijiaoChengGuoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_tijiaoChengGuoBtn addTarget:self action:@selector(tijiaochengguoBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _tijiaoChengGuoBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_tijiaoChengGuoBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:0];
        _tijiaoChengGuoBtn.backgroundColor = [UIColor colorWithHexString:@"#20B097"];
        [_tijiaoChengGuoBtn setTitle:@"提交成果" forState:UIControlStateNormal];
        _tijiaoChengGuoBtn.hidden = YES;
        _tijiaoChengGuoBtn.layer.cornerRadius = 5;
        _tijiaoChengGuoBtn.layer.masksToBounds = YES;
    }
    return _tijiaoChengGuoBtn;
}


@end


































